import axios from 'axios'
export default function (url, type, data, callBack) {
  if (type === 'get') {
    axios.get(url, {
      params: data,
      headers: {'token': JSON.parse(localStorage.getItem('userInfo')).token}
    })
      .then(function (response) {
        callBack(response.data)
      })
      .catch(function (error) {
        console.log(error)
      })
  } else if (type === 'post') {
    axios.post(url, data, {
      headers: {'token': JSON.parse(localStorage.getItem('userInfo')).token}
    })
      .then(function (response) {
        callBack(response.data)
      })
      .catch(function (error) {
        console.log(error)
      })
  } else if (type === 'put') {
    axios.put(url, data, {
      headers: {'token': JSON.parse(localStorage.getItem('userInfo')).token}
    })
      .then(function (response) {
        callBack(response.data)
      })
      .catch(function (error) {
        console.log(error)
      })
  }
}
